package com.knowledge.plus.java8.函数式接口;

import java.util.function.UnaryOperator;

/**
 * UnaryOperator<T> ：接受一个参数为类型T，返回值类型也为T
 *
 * @author TPF
 * @since 2023/12/5
 */
class UnaryOperatorDemo {

    public static void main(String[] args) {
        UnaryOperator<Integer> incrementByOne = x -> x + 1;
        UnaryOperator<Integer> multiplyByTwo = x -> x * 2;

        int result = incrementByOne.andThen(multiplyByTwo).apply(5); // 相当于 (5 + 1) * 2 = 12
        System.out.println(result); // 输出 12

        UnaryOperator<String> toUpperCase = String::toUpperCase;
        String upperCaseResult = toUpperCase.apply("hello");
        System.out.println(upperCaseResult); // 输出 HELLO
    }

}
